import path from 'path'
import type { UserConfig } from 'vitepress'
import { shared } from './config/shared'
// import { en } from './config/en'
import { zh } from './config/zh'
import { mdPlugin } from '../../plugins/plugins'
import { MarkdownTransform } from '../../plugins/markdown-transform'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'

const exPath = path.resolve(__dirname, '..')

const config: UserConfig = {
  ...shared,
  locales: {
    root: { label: '简体中文', ...zh },
    // en: { label: 'English', ...en },
  },
  // transformHead: () => {
  //   return [['script', { src: 'test.js' }] ]
  // },
  vite: {
    server: {
      port: 4007
    },
    plugins: [
      // htmlPlugin()

      // https://github.com/antfu/unplugin-vue-components
      Components({
        dirs: ['.vitepress/vitepress/components'],

        allowOverrides: true,

        // custom resolvers
        resolvers: [
          // auto import icons
          // https://github.com/antfu/unplugin-icons
          IconsResolver(),
        ],

        // allow auto import and register components used in markdown
        include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
      }),
      Icons({
        autoInstall: true,
      }),
      MarkdownTransform(),
    ],
  },
  markdown: {
    config: (md) => mdPlugin(md as any, exPath),
  }
}

export default config;

// export default defineConfig({
//   ...shared,
//   locales: {
//     root: { label: '简体中文', ...zh },
//     // en: { label: 'English', ...en },
//   },
//   // transformHead: () => {
//   //   return [['script', { src: 'test.js' }] ]
//   // },
//   vite: {
//     server: {
//       port: 4007
//     },
//     plugins: [
//       // htmlPlugin()
//     ]
//   },
//   markdown: {
//     config: (md) => mdPlugin(md as any),
//   }
// })
